/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * TrainingBook
 * Copyright (C) Arnaud Duval 2010 <arnaud.duval@gmail.com>
 * 
 * TrainingBook is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * TrainingBook is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _TRACK_SEGMENT_HPP_
#define _TRACK_SEGMENT_HPP_

#include "track-point.hpp"
#include <libxml++/libxml++.h>
#include <Duration.hpp>
#include <fstream>

///@class TrackSegment
///@brief Define a GPS track segment in GPX format
class TrackSegment
{
    public:
        TrackSegment();  //Default constructor
        TrackSegment(const TrackSegment&);  //Copy constructor
        ~TrackSegment();  //Destructor
        TrackSegment &operator=(const TrackSegment&);   //Overload of = operator
        bool ReadXMLNode(xmlpp::Node*); //Read data from a XML Node
        double Length();  //Return length of the segment in kilometers
        Duration GetDuration(); //Return duration of the segment
        DateTime GetStartDate();	//Return start date of the segment
        double TotalAscent();   //Return total ascent
        double TotalDescent();  //Return total descent
        ///@brief Append points to a distance list
        void AppendToDistanceList(std::list<double>&);
        ///@brief Append points to an elevation list
        void AppendToElevationList(std::list<double>&);
        ///@brief Append points to a speed list
        void AppendToSpeedList(std::list<double>&);
        ///@brief Append points to a latitude list
        void AppendToLatList(std::list<double>&);
        ///@brief Append points to a longitude list
        void AppendToLonList(std::list<double>&);
        ///@brief Return minimum value of elevation
        double MinElevation();
        ///@brief Return maximum value of elevation
        double MaxElevation();
        ///@brief Return maximum value of speed
        double MaxSpeed();
        ///@brief Return maximum value of latitude
        double MaxLat();
        ///@brief Return minimum value of latitude
        double MinLat();
        ///@brief Return maximum value of longitude
        double MaxLon();
        ///@brief Return minimum value of longitude
        double MinLon();
        ///@brief Write to XML file
        void WriteXML(std::ofstream&);
        ///@brief Filter the track by keeping points separated by a given distance, return the number of suppressed points
        unsigned int FilterByDistance(double);
        ///@brief Filter the track by keeping points separated by a given elevation variation, return the number of suppressed points
        unsigned int FilterByElevationVariation(double);
        ///@brief Smooth the elevation values with given buffer size
        void SmoothElevation(unsigned int);
        ///@brief Recompute the speed values
        void RecomputeSpeed();
        ///@brief Add a new point at the end of the segment
        void AddPoint(TrackPoint);
        ///@brief Write a part of the content of the track segment to the standard output for debug
        void WriteForDebug();
    protected:

    private:
        std::list<TrackPoint> points;

};

#endif // _TRACK_SEGMENT_HPP_
